<!--集团动态-->
<template>
  <el-card class="mt15 mb15">
    <div class="mb15">
      <el-button type="primary" icon="el-icon-document-add" @click="editShow('新增',null)">新增</el-button>
    </div>
    <el-table
      :data="list"
      style="width: 100%;margin-bottom: 20px;"
      row-key="code"
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >

      <el-table-column type="selection" width="50" />
      <!-- 缩略图 -->
      <el-table-column align="left" prop="label" width="250" label="岗位名称" />
      <el-table-column align="center" prop="code" label="岗位编码" />
      <!-- 操作 -->
      <el-table-column label="操作" width="150px" fixed="right" align="center">
        <template slot-scope="{row,$index}">
          <el-button type="text" @click="editShow('编辑',row)">编辑</el-button>
          <el-button type="text" @click="delItem(row,$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <editDrawer ref="editDrawer" @refresh="refresh" />
  </el-card>
</template>

<script>
import {
  list_v2,
  del_v2
} from '@/api/position'
import waves from '@/directive/waves' // waves directive
import editDrawer from './components/editDrawer'

export default {
  name: 'ComplexTable',
  components: {
    editDrawer
  },
  directives: {
    waves
  },
  data() {
    return {
      list: [], // 内容列表
      listLoading: true,
      // 查询参数
      listQuery: {
        pageNo: 1,
        pageSize: 10000
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 打开编辑弹窗
    editShow(title, rowData) { // rowData 暂未使用
      this.$refs.editDrawer.show(title, rowData)
    },
    refresh() {
      this.getList()
    },
    // 分页数据
    getList() {
      this.listLoading = true
      list_v2(this.listQuery).then(response => {
        const list = response.result
        this.list = list
        this.listLoading = false
      })
    },
    // 删除
    delItem(e, index) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const p = {
          id: e.value
        }
        del_v2(p).then(response => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.refresh()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
